#include<iostream>
#include<vector>
#include<queue>
using namespace std;
struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode() 
        : val(0), left(nullptr), right(nullptr) 
    {}
    TreeNode(int x) 
        : val(x), left(nullptr), right(nullptr) 
    {}
    TreeNode(int x, TreeNode* left, TreeNode* right) 
        : val(x), left(left), right(right) 
    {}
};
class Solution {
public:
    vector<int> largestValues(TreeNode* root) {
        if (root == nullptr)
            return {};
        vector<int> nums;
        queue<TreeNode*> q;
        q.push(root);
        int size = q.size();
        int max = INT_MIN;
        while (!q.empty())
        {
            for (int i = 0; i < size; ++i)
            {
                if (q.front()->val > max)
                    max = q.front()->val;
                if (q.front()->left)
                    q.push(q.front()->left);
                if (q.front()->right)
                    q.push(q.front()->right);
                q.pop();
            }
            nums.push_back(max);
            size = q.size();
            max = INT_MIN;
        }
        return nums;
    }
};
int main()
{

    return 0;
}